<?php
/**
 * Description:
 * Author: hezhizheng
 * Date: 2018/11/14
 * Time: 17:08
 * Created by Created by Panxsoft.
 */

namespace App\Models\Options;

use App\Models\Language;
use App\Services\Utils\ImageHelper;
use Illuminate\Database\Eloquent\Model;

/**
 * 选项值
 *
 */
class OptionValue extends Model
{
    protected $guarded = [];

    protected $table = 'option_value';
    protected $primaryKey = 'option_value_id';

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function optionValueDescription()
    {
        return $this->hasOne(OptionValueDescription::class, 'option_value_id', 'option_value_id')
            ->where('language_id', Language::getLanguageId());
    }

    /**
     * @return null|string
     */
    public function getImageAttribute()
    {
        $route = $this->attributes['image'];

        if ($route) {
            return ImageHelper::generateImagePath($route);
        } else {
            return null;
        }
    }

}